package ControlLayer;
import ModelLayer.*;
import DBLayer.*;
import java.util.ArrayList;


public class CtrProduct {

    public CtrProduct() {

    }
   
     public ArrayList getAllProducts()
    {
      IFDBProduct dbProd = new DBProduct();
      ArrayList allProd = new ArrayList();
      allProd = dbProd.getAllProducts(false);
      return allProd;
    }
    
   
    public int getMaxID()
    {
        IFDBProduct dbPro = new DBProduct();
        int id = dbPro.MaxID();
        return id;
    }
            
    public int getAllProductsNum()
   {
       IFDBProduct dbPro = new DBProduct();
       int id = dbPro.Antal();
       return id;
                
      }
   
    

    public Product findByName(String name) {
	IFDBProduct dbProd = new DBProduct();
	return dbProd.searchProductOnName(name, true);
    }

    public Product findByID(int pId)
    {
        IFDBProduct dbProd = new DBProduct();
        return dbProd.findProduct(pId, true);
    }

       public Product findSupByID(int suId)
    {
        IFDBProduct dbProd = new DBProduct();
        return dbProd.searchProductSup(suId, true);
    }
    
        public void updateProduct(String type, double price, double dimensions, 
            String placement, int minStock, int maxStock, int currentStock, 
            int productID)
    
    {
        IFDBProduct dbProd = new DBProduct();
        
        Product prod = new Product();
        
        prod.setType(type);
        prod.setPrice(price);
        prod.setDimensions(dimensions);
        prod.setPlacement(placement);
        prod.setMinStock(minStock);
        prod.setMaxStock(maxStock);
        prod.setCurrentStock(currentStock);
        prod.setProductID(productID);   
        prod.setSupplier(new Supplier(prod.getSupID()));
       
         dbProd.updateProduct(prod);
 }
    
    public void updateProductStock(int productID, int newStock)
    {
        IFDBProduct dbProd = new DBProduct();
        
        dbProd.updateProductStock(productID, newStock);
    }
    
    public void insertProduct(Product pro) 
    {
	IFDBProduct dbPro = new DBProduct();
        dbPro.insertProduct(pro);

     }
    
    public void deleteProduct(int productID)
    {
        IFDBProduct dbPro = new DBProduct();
        dbPro.deleteProduct(productID);
    }

    
      public Product findByType(String type)
    {
        IFDBProduct dbProd = new DBProduct();
        return dbProd.searchProductType(type, true);
    }
      
    
      
      
      
}